package com.woniuxy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.aspect.LogRecord;
import com.woniuxy.dao.CarInsuranceMapper;
import com.woniuxy.dto.CarInsuranceDto;
import com.woniuxy.entity.CarInsurance;
import com.woniuxy.service.CarInsuranceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
@Service
public class CarInsuranceServiceImpl implements CarInsuranceService {

    @Autowired
    private CarInsuranceMapper carInsuranceMapper;
    /**
     * 分页查
     * @param condition
     * @param pageNum   当前页
     * @param pageSize  每页大小
     * @return 分页对象
     */
    @Override
    public PageInfo<CarInsuranceDto> findByPage(Map<String, Object> condition, int pageNum, int pageSize) {
        //1.设置页码和每页大小
        PageHelper.startPage(pageNum, pageSize);
        //2.调用DAO层查询
        List<CarInsuranceDto> list = carInsuranceMapper.findAll(condition);
        //3.返回PageInfo对象
        return new PageInfo<>(list);
    }

    /**
     * 添加
     *
     * @param carInsurance
     */
    @LogRecord
    @Override
    public int save(CarInsurance carInsurance) {
        return carInsuranceMapper.save(carInsurance);
    }

    /**
     * 修改
     *
     * @param carInsurance
     */
    @LogRecord
    @Override
    public int updateById(CarInsurance carInsurance) {
        return carInsuranceMapper.updateById(carInsurance);
    }

    /**
     * 删除
     *
     * @param id
     */
    @LogRecord
    @Override
    public int deleteById(Integer id) {
        return carInsuranceMapper.deleteById(id);
    }

    /**
     * 批量删除
     *
     * @param ids
     */
    @LogRecord
    @Override
    public int deleteBatch(String[] ids) {
        return carInsuranceMapper.deleteBatch(ids);
    }

    /**
     * 导出所有数据Excel
     */
    @Override
    public List<CarInsuranceDto> findAll() {
        return carInsuranceMapper.findAll(null);
    }

    /**
     * 批量添加数据
     *
     * @param carInsuranceList
     */
    @Override
    public int insertBatch(List<CarInsuranceDto> carInsuranceList) {
        return carInsuranceMapper.insertBatch(carInsuranceList);
    }

    /***
     *查询所有保险远程绑定
     */
    @Override
    public List<CarInsuranceDto> carInsuranceList() {
        return carInsuranceMapper.carInsuranceList();
    }
}
